package liuliu.throughwaring.ui.activity;

import android.content.Intent;
import android.graphics.Bitmap;
import android.net.Uri;
import android.view.View;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import net.tsz.afinal.annotation.view.CodeNote;

import java.util.List;

import liuliu.custom.control.toolbar.TToolbar;
import liuliu.custom.method.Utils;
import liuliu.throughwaring.R;
import liuliu.throughwaring.base.BaseActivity;
import liuliu.throughwaring.model.CompanyModel;
import liuliu.throughwaring.model.PersonModel;

/**
 * 房屋详细信息页面
 * Created by Administrator on 2016/5/16.
 */
public class HouseDetailActivity extends BaseActivity {
    public static HouseDetailActivity mInstance;
    @CodeNote(id = R.id.detail_image_iv)
    ImageView detail_image_iv;
    @CodeNote(id = R.id.xiaoqu_name_tv)
    TextView xiaoqu_name_tv;
    @CodeNote(id = R.id.xiaoqu_address_tv)
    TextView xiaoqu_address_tv;
    @CodeNote(id = R.id.menpai_num_tv)
    TextView menpai_num_tv;
    @CodeNote(id = R.id.fang_name_tv)
    TextView fang_name_tv;
    @CodeNote(id = R.id.idcard_tv)
    TextView idcard_tv;
    @CodeNote(id = R.id.tel_tv)
    TextView tel_tv;
    @CodeNote(id = R.id.tel_btn, click = "onClick")
    Button tel_btn;
    @CodeNote(id = R.id.home_type_tv)
    TextView home_type_tv;
    @CodeNote(id = R.id.rent_num_tv)
    TextView rent_num_tv;
    @CodeNote(id = R.id.remark_tv)
    TextView remark_tv;
    CompanyModel model;
    @CodeNote(id = R.id.toolbar)
    TToolbar toolbar;
    @CodeNote(id = R.id.rent_num_ll, click = "onClick")
    LinearLayout rent_num_ll;

    @Override
    public void initViews() {
        setContentView(R.layout.activity_house_detail);
        model = (CompanyModel) getIntent().getSerializableExtra("CompanyModel");
        mInstance = this;
    }

    @Override
    public void initEvents() {
        xiaoqu_name_tv.setText(model.getCompanyName());
        xiaoqu_address_tv.setText(model.getCompanyAddress());
        if (model.getHMenpai() == null) {
            menpai_num_tv.setText("A座403");
        } else {
            menpai_num_tv.setText(model.getHMenpai());
        }
        fang_name_tv.setText(model.getCompanyLegalPerson());
        if (model.getHIdcard() == null) {
            idcard_tv.setText("131182910321391029");
        } else {
            idcard_tv.setText(model.getHIdcard());
        }
        tel_tv.setText(model.getCompanyPhoneNumber());
        if (model.getHHuxing() == null) {
            home_type_tv.setText("2室1厅1卫");
        } else {
            home_type_tv.setText(model.getHHuxing());
        }
        List<PersonModel> list = finalDb.findAllByWhere(PersonModel.class, "PersonCompanyId='" + model.getCompanyId() + "' and PersonStatus='CheckIn'");
        rent_num_tv.setText(list.size() + "");//承租人数
        remark_tv.setText(Utils.URLEncode(model.getCompanyComment()));
        Bitmap bitmap = Utils.getLoacalBitmap(model.getCompanyOveralImageUrl());
        if (bitmap != null) {
            detail_image_iv.setImageBitmap(bitmap);
        }
        toolbar.setLeftOnClick(new TToolbar.LeftOnClickListener() {
            @Override
            public void leftclick() {
                mInstance.finish();//关闭页面
            }
        });
    }

    public void onClick(View view) {
        switch (view.getId()) {
            case R.id.tel_btn:
                Intent intent = new Intent();
                intent.setAction(Intent.ACTION_DIAL);
                intent.setData(Uri.parse("tel:" + model.getCompanyPhoneNumber()));
                startActivity(intent);
                break;
            case R.id.rent_num_ll:
                this.finish();//关闭页面
                break;
        }
    }
}
